package com.event.binlog.config;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import com.event.binlog.iface.IBinlogRowEventHandle;
import com.event.binlog.listener.BinlogRowEventListener;
import com.event.common.constant.BinlogRowEventConst;
import com.google.common.eventbus.EventBus;

@Configuration
@ComponentScan(basePackages = {"com.event"})
@ConditionalOnProperty(name = "db.binlog.enable", havingValue = "true")
public class BinlogRowEventConfig {

    @Autowired
    private List<IBinlogRowEventHandle> binlogRowEventHandle;

    @Bean(BinlogRowEventConst.EVENT_NAME)
    public EventBus getEventBus() {
        EventBus eventBus = new EventBus(BinlogRowEventConst.EVENT_NAME);
        eventBus.register(new BinlogRowEventListener(binlogRowEventHandle));
        return eventBus;
    }

}
